import type { PluginOption } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { visualizer } from "rollup-plugin-visualizer";
import sassDts from "vite-plugin-sass-dts";
// import eslintPlugin from "vite-plugin-eslint";

import createAutoImport from "./auto-import";
import components from "./components";
import icons from "./icons";
import setupExtend from "./setup-extend";
import svgIcon from "./svg-icon";

export default (viteEnv: any, isBuild: boolean) => {
  console.log("viteEnv", viteEnv);
  const { VITE_REPORT } = viteEnv;
  const plugins: any = [];
  plugins.push(vue());
  plugins.push(vueJsx()); // jsx插件
  plugins.push(sassDts()); // 生成scss.d.ts文件
  //   plugins.push(eslintPlugin()); // esLint 报错信息显示在浏览器界面上
  VITE_REPORT &&
    plugins.push(
      visualizer({
        open: true, // 注意这里要设置为true，否则无效
        gzipSize: true,
        brotliSize: true,
        filename: "statics.html"
      }) as unknown as PluginOption
    );
  // 自动导入
  plugins.push(createAutoImport(path));
  // 自动导入组件
  plugins.push(components(path));
  // 自动导入图标
  plugins.push(icons());
  // 扩展setup语法糖
  plugins.push(setupExtend());
  // svg图标
  plugins.push(svgIcon(path, isBuild));

  return plugins;
};
